package tedu.week03.often_class;

import jdk.nashorn.internal.runtime.regexp.joni.Regex;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Locale;

/**
 * <pre>
 *  java.lang.String
 *      String类是一个字符串类对象.
 *      构造器:
 *          ①
 *          public String()
 *          public String(String original)
 *          public String(StringBuffer buffer)
 *          public String(StringBuilder builder)
 *          ②
 *          public String(byte[] bytes)
 *          public String(byte[] bytes,Charset charset)
 *          public String(byte[] bytes,String charsetName)
 *          public String(byte[] bytes,int offset,int length)
 *          public String(byte[] bytes,int offset,int length,Charset charset)
 *          public String(byte[] bytes,int offset,int length,String charsetName)
 *          ③
 *          public String(char[] value)
 *          public String(char[] value,int offset,int count)
 *          ④
 *          public String(int[] codePoints,int offset,int count)
 *
 *      方法:
 *------------------------------------------------------------------------------
 * 字符串与字符串的比较
 *          public int compareTo(String anotherString)              对象是否与参数相同,相同返回0
 *          public int compareToIgnoreCase(String str)              对象是否与参数相同,(不区分大小写)相同返回0
 *          public boolean equals(Object anObject)                  对象是否与参数相同,相同返回true
 *          public boolean equalsIgnoreCase(String anotherString)   对象是否与参数相同,(不区分大小写)相同返回true
 * ------------------------------------------------------------------------------
 * 将字符串转换成byte数组或char数组
 *          public byte[] getBytes()                                返回字符串的byte数组
 *          public byte[] getBytes(Charset charset)                 根据charset返回字符串的byte数组
 *          public byte[] getBytes(String charsetName)              根据charset字符串返回字符串的byte数组
 *          public char[] toCharArray()                             返回字符串的char数组
 * ------------------------------------------------------------------------------
 * 根据char值或字符串查找在字符串中的位置.如果没有返回-1.
 *          public int indexOf(int ch)                              返回参数下标索引的索引位置
 *          public int indexOf(int ch,int fromIndex)                从fromIndex开始,返回参数下标索引的索引位置
 *          public int indexOf(String str,int fromIndex)            从fromIndex开始,返回字符串参数下标索引的索引位置
 *          public int lastIndexOf(String str)                      返回最后一次str参数的下标索引的位置
 *          public int lastIndexOf(String str,int fromIndex)        从fromIndex开始,返回最后一次str参数的下标索引的位置
 *------------------------------------------------------------------------------
 * 字符串的替换
 *          public String replace(char oldChar,char newChar)                        将后面的newChar替换掉前面的oldChar(所有都替换)
 *          public String replace(CharSequence target,CharSequence replacement)     将后面的replacement替换掉前面的target(所有都替换)
 *          public String replaceAll(String regex,String replacement)               将后面的newChar替换掉前面的regex表达式(所有都替换)
 *          public String replaceFirst(String regex,String replacement)             将后面的newChar替换掉前面的oldChar(只替换一个)
 *------------------------------------------------------------------------------
 * 字符串的分割
 *          public String[] split(String regex)                 以regex将字符串分割为String数组
 *          public String[] split(String regex,int limit)       以regex将字符串分割为limit长度的String数组
 * ------------------------------------------------------------------------------
 * 字符串的剪切
 *          public CharSequence subSequence(int beginIndex,int endIndex)    将字符串从beginIndex到endIndex剪切成新的字符串
 *          public String substring(int beginIndex)                         将字符趾从beginIndex开始剪切成新的字符串
 *          public String substring(int beginIndex,int endIndex)            将字符串从beginIndex到endIndex剪切成新的字符串
 * ------------------------------------------------------------------------------
 * 其它简单方法
 *          public String concat(String str)                        对象连接参数生成新的字符串
 *          public boolean contains(CharSequence s)                 对象是否包含参数字符串
 *          public boolean contentEquals(CharSequence cs)           对象是否包含并与参数相同
 *          public int length()                                     返回字符串的长度
 *          public int hashCode()                                   返回字符串的hashCode值
 *          public boolean isEmpty()                                判断字符串是否为空
 *          public String toString()                                返回对象的字符串表达方式
 *          public String trim()                                    去除字符串前缀及后缀的空格
 *------------------------------------------------------------------------------
 * 判断字符串的开始及结尾
 *          public boolean startsWith(String prefix)                检测字符串是否是以prefix以开始
 *          public boolean startsWith(String prefix,int offset)     检测字符串从offset开始是否是以prefix以开始
 *          public boolean endsWith(String suffix)                  检测字符串是否是以suffix为结尾
 * ------------------------------------------------------------------------------
 * 字符串的大小写转换
 *          public String toLowerCase()                             将字符串全部转换成小写
 *          public String toLowerCase(Locale locale)                将字符串以local地址的语言环境转换成小写
 *          public String toUpperCase()                             将字符串全部转换成大写
 *          public String toUpperCase(Locale locale)                将字符串以local地址的语言环境转换成大写
 *------------------------------------------------------------------------------
 * 根据索引查找对应的char值.
 *          public char charAt(int index)                           返回参数索引的char值
 *          public int codePointAt(int index)                       返回参数索引的Unicode值
 *          public int codePointBefore(int index)                   返回参数索引前一个Unicode值
 *          public int codePointCount(int beginIndex,int endIndex)  返回beginIndex到endIndex之间的Unicode值的数量
 *          public int offsetByCodePoints(int index,int codePointOffset)返回从index到codePointOffset偏差值的实际下标索引
 *------------------------------------------------------------------------------
 * 数据类型向字符串的转换
 *          public static String valueOf(boolean b)                         将b转换成字符串
 *          public static String valueOf(char c)                            将c转换成字符串
 *          public static String valueOf(char[] data)                       将data转换成字符串
 *          public static String valueOf(char[] data,int offset,int count)  将data从offset开始,count个转换成字符串
 *          public static String valueOf(int i)                             将i转换成字符串
 *          public static String valueOf(long l)                            将l转换成字符串
 *          public static String valueOf(float f)                           将f转换成字符串
 *          public static String valueOf(double d)                          将d转换成字符串
 *          public static String valueOf(Object obj)                        将obj转换成字符串
 * ------------------------------------------------------------------------------
 * 从char数组中copy字符组成新的字符串
 *          public static String copyValueOf(char[] data)                           拷备一个char数组生成字符串
 *          public static String copyValueOf(char[] data,int offset,int count)      拷备一个char数组从offset开始,复制count个生成字符串
 *------------------------------------------------------------------------------
 *          public boolean matches(String regex)                            判断字符串是否匹配参数的表达式
 ********public int offsetByCodePoints(int index,int codePointOffset)    代码与代码单元的索引
 * </pre>
 *
 * @author : resty
 * @date : 2019年06月01日    10时
 **/
public class Week03_String {
    public static void main(String[] args){
        String str = "abcabc";
//        str = str.replace("abc", "bbb");
        str = str.toLowerCase(Locale.US);
        System.out.println(str);


//        String str = "/uD835/uDD6B";
//        System.out.println(str.length());//实际字符串的长度.
//        System.out.println(str.offsetByCodePoints(0, 2));//代码点


//        String regex = "[a-z]{6,16}@[^\\s]*[.com|.cn|.com.cn|net]";
//        String mail = "abcass@163.cn";
//        System.out.println(mail.matches(regex));


/*          public static String copyValueOf(char[] data)
 *          public static String copyValueOf(char[] data,int offset,int count)
 *          public static String format(Locale l,String format,Object... args)
 *          public static String format(String format,Object... args)
 *          public void getChars(int srcBegin,int srcEnd,char[] dst,int dstBegin)
 *------------------------------------------------------------------------------*/
//        char chars[] = {'a','b','c','d','e'};
//        System.out.println(String.copyValueOf(chars,1,3));



//        String str = "abc好";
//        byte bytes [] = new byte[0];
//        bytes = str.getBytes(Charset.forName("UTF-8"));
//        for (int i = 0; i < bytes.length; i++) {
//            System.out.println(bytes[i]);
//        }
//        char chars [] = str.toCharArray();
//        for (char aChar : chars) {
//            System.out.println(aChar);
//        }


//        String str = "abcdefghijklmn";
//        System.out.println(str.offsetByCodePoints(13,-13));
//        String str = "abc";
//        String str1 = str.concat("def");
//        System.out.println(str1);
//        System.out.println(str1.contains("abc"));
//        System.out.println(str1.contentEquals("abcdef"));
//
//        String str2 = "ABC";
//        System.out.println(str.compareTo(str2));
//        System.out.println(str.compareToIgnoreCase(str2));
//        System.out.println(str.equals(str2));
//        System.out.println(str.equalsIgnoreCase(str2));
//
//        String str3 = "     abc   ";
//        str3 = str.trim();
//        System.out.println(str3);

    }




//    public static void main(String[] args){
//      /**构造器①**/
//        /*① public String()*/
//        String str1 = new String();
//        System.out.println(str1);
//        /*① public String(String original)*/
//        String str2 = new String("这是一个字符串");
//        System.out.println(str2);
//        /*① public String(StringBuffer buffer)*/
//        StringBuffer stringBuffer = new StringBuffer("test");
//        String str3 = new String(stringBuffer);
//        System.out.println(str3);
//        /*① public String(StringBuilder builder)*/
//        StringBuilder stringBuilder = new StringBuilder("test");
//        String Str4 = new String(stringBuffer);
//        System.out.println(Str4);
//        /*② public String(byte[] bytes)*/
//        byte bytes[] = {97,92,93,127,95,96,97};
//        String str5 = new String(bytes);
//        System.out.println(str5);
//        /*② public String(byte[] bytes,Charset charset)*/
//        String str6 = new String(bytes, Charset.forName("GBK"));
//        System.out.println(str6);
//        /*② public String(byte[] bytes,String charsetName)*/
//        try {
//            String str7 = new String(bytes, "GBK");
//            System.out.println(str7);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        /*② public String(byte[] bytes,int offset,int length)*/
//        String str8 = new String(bytes, 3, 4);
//        System.out.println(str8);
//        /*② public String(byte[] bytes,int offset,int length,Charset charset)*/
//        String str9 = new String(bytes, 1, 3, Charset.forName("GBK"));
//        System.out.println(str9);
//        /*② public String(byte[] bytes,int offset,int length,String charsetName)*/
//        try {
//            String str10 = new String(bytes, 0, 3, "utf-8");
//            System.out.println("str10==" + str10);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//
//        /*③ public String(char[] value)*/
//        char [] chars = {'a','b','c','d','e','f'};
//        String str11 = new String(chars);
//        /*③ public String(char[] value,int offset,int count)*/
//        String str12 = new String(chars, 0, 5);
//        System.out.println(str12);
//        /*④ public String(int[] codePoints,int offset,int count)*/
//        int ints [] = {111,1111,2222,3333,4444};
//        String str13 = new String(ints, 0, 3);
//        System.out.println(str13);
//    }
}
